import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { apiSafe, type Meta } from "@/lib/api"; import { PartyLogo } from "@/components/party"; import { Badge, Card, Empty } from "@/components/ui"; import { PARTY_IDS, partyVar, partyName } from "@/lib/parties"; export const revalidate = 300; interface Proposals { proposals: { id: number; party: string; topic: string; topicLabel: string; subtopic: string | null; proposal: string; position: string | null; direction: string | null; magnitude: string | null; page: number | null; quote: string; confidence: number; document: { id: number; title: string | null; url: string | null; type: string | null } }[] } export async function generateMetadata({ params }: { params: Promise<{ topic: string }> }): Promise { const { topic } = await params; const meta = await apiSafe("/api/meta"); const label = meta?.topics[topic]; return { title: label ? `${label} — positions des partis` : "Enjeu", description: `Ce que proposent les partis sur ${label ?? "cet enjeu"} d'après leurs documents officiels, avec page et citation.` }; } export default async function Page({ params }: { params: Promise<{ topic: string }> }) { const { topic } = await params; const [meta, data] = await Promise.all([apiSafe("/api/meta"), apiSafe(`/api/proposals?topic=${topic}&limit=400`)]); if (!meta || !meta.topics[topic]) notFound(); if (!data) return ; const by: Record = {}; data.proposals.forEach((p) => { (by[p.party] ??= []).push(p); }); return (
← Enjeux

{meta.topics[topic]}

{data.proposals.length} propositions extraites des documents officiels. L'absence d'un parti signifie qu'aucun document ingéré n'aborde le sujet.

{PARTY_IDS.map((id) => (
{partyName(id)}{by[id]?.length ?? 0}
{(by[id] ?? []).length === 0 &&
Aucune proposition documentée.
} {(by[id] ?? []).map((p) => (
{p.proposal}
{p.magnitude &&
{p.magnitude}
}
« {p.quote.length > 240 ? p.quote.slice(0, 240) + "…" : p.quote} »
{p.document.title ?? "Document"}{p.page ? `p. ${p.page} · ` : ""}{Math.round(p.confidence * 100)} %
{p.direction && p.direction !== "neutre" &&
{p.direction.replace(/_/g, " ")}
}
))}
))}
); }